package com.shinbada.core.security.openapi;

import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author initcap
 * @date Created in 2020/10/20 13:44.
 */
@Getter
@Setter
public class OpenApiClient {

    private String clientId;

    private String clientName;

    private String secureKey;

    private List<String> ipWhiteList;

    private Signature signature;

    public boolean verifyIpAddress(String ipAddress) {
        if (CollectionUtils.isEmpty(ipWhiteList) || StringUtils.isEmpty(ipAddress)) {
            return true;
        }
        if (ipAddress.contains(" ")) {
            ipAddress = ipAddress.split("[ ]")[0].trim();
        }
        return ipWhiteList.contains(ipAddress);
    }

}
